package com.lrkj.payfee.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.payfee.domain.RuleCost;
import com.lrkj.payfee.domain.vo.AdueRecordVo;
import com.lrkj.payfee.service.IRuleCostService;
import com.lrkj.payfee.vo.ChangeFeeVo;
import com.lrkj.payfee.vo.DemolitionVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 常规费用单Controller
 *
 * @author yajun_ren
 * @date 2021-07-30
 */
@RestController
@RequestMapping("/payfee/ruleCost")
public class RuleCostController extends BaseController {
    @Autowired
    private IRuleCostService ruleCostService;

    /**
     * 查询费用单列表
     */
    @ApiOperation(value = "查询费用单列表", notes = "查询费用单列表")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:list')")
    @GetMapping("/list")
    public TableDataInfo list(RuleCost ruleCost) {
        startPage();
        List<RuleCost> list = ruleCostService.selectRuleCostList(ruleCost);
        return getDataTable(list);
    }

    /**
     * 导出常规费用单列表
     */
    @ApiOperation(value = "导出费用单列表", notes = "导出费用单列表")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:export')")
    @Log(title = "费用单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RuleCost ruleCost) {
        List<RuleCost> list = ruleCostService.selectRuleCostList(ruleCost);
        ExcelUtil<RuleCost> util = new ExcelUtil<RuleCost>(RuleCost.class);
        return util.exportExcel(list, "常规费用单数据");
    }

    /**
     * 获取常规费用单详细信息
     */
    @ApiOperation(value = "获取费用单详细信息", notes = "获取费用单详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:query')")
    @GetMapping(value = "/{costId}")
    public AjaxResult getInfo(@PathVariable("costId") String costId) {
        return AjaxResult.success(ruleCostService.selectRuleCostById(costId));
    }


    /**
     * 费用单 拆分 修改
     */
    @ApiOperation(value = "费用单拆分/修改", notes = "费用单拆分/修改")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:free')")
    @Log(title = "费用单拆分/修改", businessType = BusinessType.INSERT)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody List<RuleCost> ruleCost) {
        return AjaxResult.success(ruleCostService.edit(ruleCost));
    }


    /**
     * 新增费用单
     */
    @ApiOperation(value = "新增费用单", notes = "新增费用单")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:add')")
    @Log(title = "常规费用单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RuleCost ruleCost) {
        return toAjax(ruleCostService.insertRuleCost(ruleCost));
    }

    /**
     * 删除常规费用单
     */
    @ApiOperation(value = "删除费用单", notes = "删除费用单")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:remove')")
    @Log(title = "常规费用单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{costIds}")
    public AjaxResult remove(@PathVariable String[] costIds) {
        return toAjax(ruleCostService.deleteRuleCostByIds(costIds));
    }

    /**
     * 新增常规费用单
     */
    @ApiOperation(value = "创建费用单", notes = "创建费用单")
    @Log(title = "常规费用单", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:createRuleCost')")
    @PostMapping("/createRuleCost")
    public AjaxResult createRuleCost(@RequestBody RuleCost ruleCost) {
        return toAjax(ruleCostService.createRuleCost(ruleCost));
    }


    /**
     * 查询常规费用单列表
     */
    @ApiOperation(value = "查询房间费用", notes = "查询房间费用")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:selectAdueRecord')")
    @GetMapping("/selectAdueRecord")
    public AjaxResult selectAdueRecord(AdueRecordVo adueRecordVo) {
        return AjaxResult.success(ruleCostService.selectAdueRecord(adueRecordVo));
    }


    /**
     * 保证金退款
     */
    @ApiOperation(value = "保证金退款", notes = "保证金退款")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:bailRefund')")
    @GetMapping("/bailRefund")
    public AjaxResult bailRefund(AdueRecordVo adueRecordVo) {
        return AjaxResult.success(ruleCostService.bailRefund(adueRecordVo));
    }

    @ApiOperation(value = "费用管理改费", notes = "费用管理改费")
    @Log(title = "费用管理改费", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:changeFee')")
    @PostMapping("/changeFee")
    public AjaxResult changeFee(@RequestBody ChangeFeeVo changeFeeVo) {
        return toAjax(ruleCostService.changeFee(changeFeeVo));
    }


    @ApiOperation(value = "费用管理拆费", notes = "费用管理拆费")
    @PreAuthorize("@ss.hasPermi('payfee:ruleCost:demolitionFee')")
    @Log(title = "费用管理拆费", businessType = BusinessType.UPDATE)
    @PostMapping("/demolitionFee")
    public AjaxResult demolitionFee(@RequestBody DemolitionVo demolitionVo) {
        return toAjax(ruleCostService.demolitionFee(demolitionVo));
    }


}
